//index.js
//获取应用实例
const time = require("../../utils/util.js");//引入时间转换
const app = getApp()
Page({
  data: {
    host: '',
    title: ["进行中", "已结束"],
    lotteryList: []	//活动列表	
  },
  onLoad: function () {
    var that=this
    that.setData({
      host:app.globalData.ip
    })
    that.getLotteryList()
  },
  /**
   * 跳转详细页面
   */
  toDetail: function (e) {
    console.log(e.currentTarget.dataset.acid)
    var acid = e.currentTarget.dataset.acid;
    if (app.globalData.userInfo) {
      wx.navigateTo({
        url: '../detail/detail?acid=' + acid,
      })
    } else {
      wx.showModal({
        title: '未授权！',
        content: '请先提供授权信息~',
        showCancel: false,
      })
    }
    
  },
  //获取活动列表
  getLotteryList: function (e) {
    var that = this
    console.log("获取活动列表", that.data.host + '/jeesite/lottery/activity')
    wx.request({
      url: that.data.host +'/jeesite/lottery/activity',
      method:"POST",
      header:{
        "Content-Type":  "application/json"
      },
      data:{
        "message":"getAll"
      },
      success: function (res) {
        console.log(res)
        if(res.data.code==0){
          var list = res.data.data
          var currenttime=''
          for(let i=0;i<list.length;i++){
            currenttime = list[i].end_time
            list[i].end_time = time.formatTime(currenttime, 'Y-M-D h:m:s')
          }
          that.setData({
            lotteryList: list
          })
          console.log("获取列表成功" ,that.data.lotteryList)
        }else{
          console.log("获取失败 ", res)
        }
      },
      fail: function (res) {
        console.log("获取失败 ", res)
      }
    })
    // 隐藏导航栏加载框
    wx.hideNavigationBarLoading();
    // 停止下拉动作
    wx.stopPullDownRefresh();
  },
  //下拉刷新
  onPullDownRefresh: function(e){
    var that =this
    wx.showNavigationBarLoading();
    that.getLotteryList();
  }
})
